{% extends 'users/user-base.html' %}

{% load static %}
{% block title %}控制台{% endblock %}
{% block custom_css %}
    <style>
        td{
            vertical-align:middle !important;
        }
    </style>
{% endblock %}

{% block custom_js %}{% endblock %}

{% block content %}
    <script type="text/javascript">
        $(document).ready(function () {

            $("#tab").on("click", ":button", function (event) {
                 var vm_name = $(this).closest("tr").find("td").eq(2).text();
                var snapshot_name = $(this).closest("tr").find("td").eq(3).text();
                console.log(vm_name);
                var btn_id=$(this).attr('id');
                if (btn_id == 'delete'){
                    $.ajax({
                    type: "POST",
                    data: {'vm_name': vm_name,'snapshot_name':snapshot_name},
                     url: "/admins/snapshot_delete/",
                    success: function (data) {
                        if (data["st"] === 1) {
                            alert("成功");
                            window.location.reload();
                        } else if (data["st"] === 2) {
                            alert("Failed to delete snapshot");
                        }
                    },
                    error: function () {
                        alert("false");
                    }
                })
                }
                if(btn_id == 'revert'){
                    $.ajax({
                    type: "POST",
                    data: {'vm_name': vm_name,'snapshot_name':snapshot_name},
                    url: "/users/snapshotRevert/",
                    success: function (data) {
                        if (data["st"] === 1) {
                            alert("成功");
                            window.location.reload();
                        } else if (data["st"] === 2) {
                            alert("Failed to revert virtual machine");
                        }
                    },
                    error: function () {
                        alert("false");
                    }
                })
                }

                });
        })
    </script>

    <div class="down-main">
        <div class="left-main left-full">
            <div class="sidebar-fold"><span class="glyphicon glyphicon-menu-hamburger"></span></div>
            <div class="subNavBox">
                <div class="sBox">
                    <div class="subNav sublist-down"><span
                            class="title-icon glyphicon glyphicon-chevron-down"></span><span class="sublist-title">云计算基础服务</span>
                    </div>
                    <ul class="navContent" style="display:block">
                        <li >
                            <div class="showtitle" style="width:100px;">我的云主机</div>

                            <a href="{% url 'users:usercontrol' %}"><span
                                    class="sublist-icon glyphicon glyphicon-cloud"></span><span
                                    class="sub-title">我的云主机</span></a>
                        </li>
<!--                         <li >-->
<!--                            <div class="showtitle" style="width:100px;">我的备份</div>-->

<!--                            <a href="{% url 'users:snapshotlist' %}"><span-->
<!--                                    class="sublist-icon glyphicon glyphicon-cloud"></span><span-->
<!--                                    class="sub-title">我的备份</span></a>-->
<!--                        </li>-->
                        <li >
                            <div class="showtitle" style="width:100px;">我的容器</div>

                            <a href="{% url 'users:container_list' %}"><span
                                    class="sublist-icon glyphicon glyphicon-cloud"></span><span
                                    class="sub-title">我的容器</span></a>
                        </li>
                        <li >
                            <div class="showtitle" style="width:100px;">虚拟机申请记录</div>

                            <a href="{% url 'users:vmcheck' %}"><span
                                    class="sublist-icon glyphicon glyphicon-cloud"></span><span
                                    class="sub-title">虚拟机申请记录</span></a>
                        </li>
<!--                         <li >-->
<!--                            <div class="showtitle" style="width:100px;">端口申请记录</div>-->

<!--                            <a href="{% url 'users:portRecords' %}"><span-->
<!--                                    class="sublist-icon glyphicon glyphicon-check"></span><span-->
<!--                                    class="sub-title">端口申请记录</span></a>-->
<!--                        </li>-->
                        <li >
                            <div class="showtitle" style="width:100px;">配置申请记录</div>

                            <a href="{% url 'users:configurationRecords' %}"><span
                                    class="sublist-icon glyphicon glyphicon-check"></span><span
                                    class="sub-title">配置申请记录</span></a>
                        </li>
                    </ul>
                </div>

            </div>
        </div>

        <div class="dashboard-wrapper">
            <div class="dashboard-ecommerce">
                <div class="container-fluid dashboard-content ">
                    <!-- ============================================================== -->
                    <!-- pageheader  -->
                    <!-- ============================================================== -->
                    <div class="row">
                        <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                            <div class="page-header">
                                <h2 class="pageheader-title">我的备份</h2>
                                <div class="page-breadcrumb">
                                    <nav aria-label="breadcrumb">
                                        <ol class="breadcrumb">
                                            <li class="breadcrumb-item">云计算基础服务</li>
                                            <li class="breadcrumb-item active" aria-current="page">我的备份</li>
                                        </ol>
                                    </nav>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- ============================================================== -->
                    <!-- end pageheader  -->
                    <!-- ============================================================== -->

                    <div class="row">
                        <!-- ============================================================== -->
                        <!-- basic table  -->
                        <!-- ============================================================== -->
                        <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                            <div class="card">
                                <div class="card-body">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-bordered first" id="tab">
                                            <thead>
                                            <tr>
                                                <th >ID</th>
                                                <th >用户</th>
                                                <th >虚拟机</th>
                                                <th>快照名</th>
                                                <th>创建时间</th>
                                            </tr>
                                            </thead>
                                            {% for snapshot in snapshots %}
                                                <tr>
                                                    <td>{{ forloop.counter }}</td>
                                                    <td><a href="">{{ snapshot.username.username }}</a></td>
                                                    <td>{{ snapshot.vmname.name }}</td>
                                                    <td>{{ snapshot.snapshotName }}</td>
                                                    <td>{{ snapshot.start_time }}G</td>
                                                    <td>
                                                            <button type="button" id="delete" class="btn btn-danger">
                                                                <span class="glyphicon glyphicon-trash">删除</span></button>
                                                    </td>
                                                   <td>
                                                          <button type="button" id="revert" class="btn btn-info">
                                                              <span class="fa fa-camera">恢复</span></button>
                                                    </td>
                                                </tr>
                                            {% endfor %}
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>






{% endblock %}



